﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Najak.Editor
{
    public partial class Yes_No : Form
    {

        static public Yes_No Instance;
        static private Point? s_LastLocation;

        private bool _isActive;


        static public bool GetAnswer(string question)
        {
			  App.Instance.PauseRendering = true;

			  try
			  {
				  Yes_No win = new Yes_No(question);
				  DialogResult result = win.ShowDialog();
				  return (result == DialogResult.Yes);
			  }
			  finally
			  {
				  App.Instance.PauseRendering = false;
			  }
        }

        public Yes_No(string question)
        {
            Instance = this;
            InitializeComponent();
            textBox1.Text = question;
        }


        protected override void OnShown(EventArgs e)
        {
            if (s_LastLocation.HasValue)
                Location = s_LastLocation.Value;

            _isActive = true;
            base.OnShown(e);
            App.IsKeyboardDisabled = true;
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            Instance = null;
            s_LastLocation = Location;
            _isActive = false;
            base.OnClosing(e);
            App.IsKeyboardDisabled = false;
        }

        private void YesButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void NoButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
    }
}
